import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { configParams } from '../storage-config';

@Injectable({
  providedIn: 'root'
})
export class StoragePurchaseManageService {

  headers = configParams.headers;

  serviceUrls: any = {
    queryPurchaseListUrl: '/purchase/list', // 查询采购单list
    deletePurchaseUrl: '/purchase/delete', // 采购单 - 删除
    queryPurchaseDetailUrl: '/purchaseDetails/list', // 采购单 - 详情
    savePurchaseUrl: '/purchase/save', // 出库单 - 新增
    editPurchaseUrl: '/purchase/update', // 出库单 - 编辑
    examinePurchaseUrl: '/purchase/audit', // 提交审核 | 审核

    tovoidPurchaseUrl: '/purchaseDetails/nullify', // 采购单 - 作废
  };

  constructor(public httpClient: HttpClient) { }

  // 查询采购单list
  getPurchaseList(params: any) {
    return this.httpClient.post(this.serviceUrls.queryPurchaseListUrl, params, {headers: this.headers}).toPromise();
  }

  // 采购单 - 删除
  deletePurchaseItem(params: any) {
    return this.httpClient.post(this.serviceUrls.deletePurchaseUrl, params, {headers: this.headers}).toPromise();
  }

  // 审核 | 提交审核
  examinePurchaseItem(params: any) {
    return this.httpClient.post(this.serviceUrls.examinePurchaseUrl, params, {headers: this.headers}).toPromise();
  }
  
  // 查询采购单 详情
  getPurchaseDetailData(params: any) {
    return this.httpClient.post(this.serviceUrls.queryPurchaseDetailUrl, params, {headers: this.headers}).toPromise();
  }

  // 新增 | 编辑 采购单
  updatePurchaseData(params: any) {
    let url = params.purchase.id ? this.serviceUrls.editPurchaseUrl : this.serviceUrls.savePurchaseUrl;
    return this.httpClient.post(url, params, {headers: this.headers}).toPromise();
  }

  // 采购单 - 作废
  tovoidPurchaseData(params: any) {
    return this.httpClient.post(this.serviceUrls.tovoidPurchaseUrl, params, {headers: this.headers}).toPromise();
  }
}



